<?php
/**
 * Created by PhpStorm.
 * User: 六花
 * Date: 2019/4/27
 * Time: 17:20
 */

namespace Api\Controller;

use Think\Controller;


class StoreController extends Controller {

    public  function  __construct()
    {

    }

    public function editStoreState(){
        $GLOBALS['HTTP_RAW_POST_DATA'] = stripslashes($GLOBALS['HTTP_RAW_POST_DATA']);
        $GLOBALS['HTTP_RAW_POST_DATA'] = str_replace('"[','[',$GLOBALS['HTTP_RAW_POST_DATA']);
        $GLOBALS['HTTP_RAW_POST_DATA'] = str_replace(']"',']',$GLOBALS['HTTP_RAW_POST_DATA']);
        $_POST = json_decode($GLOBALS['HTTP_RAW_POST_DATA'],true);
        if(!$_POST['Vendor'] || !is_array($_POST['Vendor'])){
            $return_array = array(
                'MessageCode' => '2',
                'Method' => 'ReceiveVendor',
                'ErrorMsg' => '参数错误',
            );
            echo json_encode($return_array,JSON_UNESCAPED_UNICODE);
            exit;
        }
        if(!$_POST['Vendor']['ExternId']){
            $return_array = array(
                'MessageCode' => '2',
                'Method' => 'ReceiveVendor',
                'ErrorMsg' => '店铺id不能为空',
            );
            echo json_encode($return_array,JSON_UNESCAPED_UNICODE);
            exit;
        }
        if($_POST['Vendor']['IsBounded'] == 1){
            $data['state'] = 1;
            $data['sync_state'] = 2;
            $result = M('store')->where(array('store_id'=>$_POST['Vendor']['ExternId']))->find();
            if(!$result){
                $return_array = array(
                    'MessageCode' => '2',
                    'Method' => 'ReceiveVendor',
                    'ErrorMsg' => '店铺不存在',
                );
                echo json_encode($return_array,JSON_UNESCAPED_UNICODE);
                exit;
            }
            $res = M('store')->where(array('store_id'=>$_POST['Vendor']['ExternId']))->save($data);
            if($res === false){
                $return_array = array(
                    'MessageCode' => '2',
                    'Method' => 'ReceiveVendor',
                    'ErrorMsg' => '修改店铺状态失败',
                );
                echo json_encode($return_array,JSON_UNESCAPED_UNICODE);
                exit;
            }
        }

        $return_array = array(
            'MessageCode' => '1',
            'Method' => 'ReceiveVendor',
            'ErrorMsg' => '修改店铺状态成功',
        );
        echo json_encode($return_array,JSON_UNESCAPED_UNICODE);
        exit;

    }

}
